package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.issue.bo.IssueAskBo;
import com.cskaoyan.bean.issue.po.IssuePo;
import com.cskaoyan.bean.issue.vo.IssueInfoVo;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通用问题模块
 * @author LiangRuiJiang
 * @since 2022/06/04  17:45
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;

    /**
     * 显示问题列表
     * @param param
     * @param question
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BaseParam param, String question){
        IssueInfoVo issueInfoVo = issueService.query(param,question);

        return BaseRespVo.ok(issueInfoVo);
    }

    /**
     * 创建问题信息
     * @param issueAskBo
     * @return
     */
    @RequestMapping(value = "create",method = RequestMethod.POST)
    public BaseRespVo create(@RequestBody() IssueAskBo issueAskBo){

        IssuePo issuePo = issueService.addIssue(issueAskBo);

        return BaseRespVo.ok(issuePo);
    }

    /**
     * 编辑问题信息
     * @param issuePo
     * @return
     */
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public BaseRespVo update(@RequestBody() IssuePo issuePo){
        //这里Po可以复用
        IssuePo issueAfterUpdate = issueService.updateIssue(issuePo);
        return BaseRespVo.ok(issueAfterUpdate);
    }

    /**
     * 根据id删除问题信息
     * @param issuePo
     * @return
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public BaseRespVo delete(@RequestBody() IssuePo issuePo){
        issueService.deleteIssue(issuePo);
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

}
